﻿using System;

namespace ClassLibrary1
{


    public class Item
    {
        public Item(int price)
        {
            if(price < 0)
                throw new ArgumentOutOfRangeException("price");

            Price = price;
        }

        public int Price { get; set; }
    }

    public class Book : Item
    {
        public Book(string author, string title, int price)
            : base(price)
        {
            if (author == null)
                throw new ArgumentNullException("author");
            title.ThrowIfNullOrEmpty("title");

            Author = author;
            Title = title;
        }

       public Book(string author, string title, int price, string publisher, int? year = default(int?))
            : this(author, title, price)
        {
            Publisher = publisher;
            Year = year;
        }

        public string Author { get; private set; }

        public string Title { get; private set; }

        public string Publisher { get; private set; }

        public int? Year { get; private set; }

        public string FormTitle()
        {
            string title = string.Format("{0}",  Title);
            if (!string.IsNullOrEmpty(Publisher))
                title = string .Format("{0} [{1}]", title, Publisher);

            if (Year.HasValue)
                title = string.Format("{0} [{1}]", title, Year);

            return title;
        }
    }
}